home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1997 February / PC Shareware 1997-02.iso / programy / e! / api / prjpick.c_ / prjpick.C
Encoding:
C/C++ Source or Header  |  1995-03-05  |  5.1 KB  |  206 lines

  1. /*************************************************
  2. *                         *
  3. * E! for Windows                 *
  4. * (c) - MainSOft sarl - 1995             *
  5. *                         *
  6. * PRJPICK Extension DLL - version 1.0         *
  7. *                         *
  8. * Display picklist of Project files.         *
  9. *                         *
  10. *************************************************/
  11.  
  12. /*
  13. PRJPICK is an Extension DLL allowing to display your project
  14. files as specified in EW.PRJ and to select a file for
  15. editing. It works even if your Project file contains
  16. file specifications with wildcards.
  17.  
  18. PRJPICK needs a new function of the E! API: EWGetPrjName.
  19. This function exists only since version E! version 2.02.
  20.  
  21. PRJPICK only exports an EWExecute function. So you just have
  22. to assign this DLL to a key or to a User Menu item to
  23. install it after copying PRJPICK.EWD to your \EW\USER
  24. directory.
  25.  
  26. Enjoy!
  27.  
  28. Patrick Philippot
  29. 08-02-95
  30. */
  31.  
  32. #include <windows.h>
  33. #include "ewapi2.h"
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <dos.h>
  38.  
  39.  
  40. #define id_ListBox  100
  41.  
  42.   char PrjName[_MAX_PATH];
  43.   char FileName[_MAX_PATH];
  44.   HWND ListBoxHandle, OkBtHandle;
  45.   HANDLE hInst;
  46.  
  47.   struct _find_t c_file;
  48.   char     drive[_MAX_DRIVE];
  49.   char     dir[_MAX_DIR];
  50.   char     fname[_MAX_FNAME];
  51.   char     ext[_MAX_EXT];
  52.   char     buffer[_MAX_PATH];
  53.  
  54.   char     szError[] = "Error!";
  55.  
  56.  
  57. BOOL CALLBACK ChoiceDlg(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  58. //  This is the dialog procedure managing the list of files
  59. {
  60.   int    Index;
  61.   FILE* Prj;
  62.  
  63.   switch (Message)
  64.   {
  65.     case WM_INITDIALOG:
  66.     // Get handle of Listbox
  67.     ListBoxHandle = GetDlgItem(hwndDlg, id_ListBox);
  68.     OkBtHandle = GetDlgItem(hwndDlg, IDOK);
  69.     EnableWindow(OkBtHandle, FALSE);
  70.     SetFocus(ListBoxHandle);
  71.     // Open Project file
  72.     if ((Prj = fopen(PrjName, "r")) == NULL)
  73.     {
  74.       EWMessageBox(GetFocus(),
  75.                "Couldn't open Project File.",
  76.                szError,
  77.                MB_OK | MB_ICONEXCLAMATION);
  78.  
  79.       return TRUE;
  80.     }
  81.     // Read lines and add filename to Listbox
  82.     while (fgets(FileName, sizeof(FileName), Prj))
  83.     {
  84.        int len = _fstrlen(FileName);
  85.  
  86.        // Remove /n included by fgets
  87.        if ((len > 0) && (FileName[len - 1] == '\n'))
  88.          FileName[len - 1] = 0;
  89.  
  90.        if (_fstrchr(FileName, '=') == NULL)
  91.        {
  92.          if ((_fstrchr(FileName, '*') == NULL) && (_fstrchr(FileName, '?') == NULL))
  93.          // The filename contains no wildcards
  94.          {
  95.            AnsiLower(FileName);
  96.            SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) FileName);
  97.          }
  98.          else
  99.          {
  100.            _splitpath(FileName, drive, dir, fname, ext);
  101.  
  102.            if (dir[0] == 0)
  103.            // The filename doesn't contain a path. Use the path of the project file
  104.            {
  105.          _splitpath(PrjName, drive, dir, fname, ext);
  106.          _fstrcpy(fname, FileName);
  107.          _fstrcat(_fstrcat(_fstrcpy(FileName, drive), dir), fname);
  108.            }
  109.  
  110.            if (_dos_findfirst(FileName, _A_RDONLY, &c_file) == 0)
  111.            {
  112.          // Enumerate files
  113.          _fstrcat(_fstrcat(_fstrcpy(buffer, drive), dir), c_file.name);
  114.          AnsiLower(buffer);
  115.          SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) buffer);
  116.          while (_dos_findnext(&c_file) == 0)
  117.          {
  118.            _fstrcat(_fstrcat(_fstrcpy(buffer, drive), dir), c_file.name);
  119.            AnsiLower(buffer);
  120.            SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) buffer);
  121.          }
  122.            }
  123.          }
  124.        }
  125.     }
  126.     fclose(Prj);
  127.     return TRUE;
  128.  
  129.     case WM_COMMAND:
  130.     switch (wParam)
  131.     {
  132.       case id_ListBox:
  133.           if (HIWORD(lParam) != LBN_DBLCLK)
  134.          // A double_click is processed as the IDOK command
  135.           {
  136.         if (HIWORD(lParam) == LBN_SELCHANGE)
  137.         {
  138.           EnableWindow(OkBtHandle, TRUE);
  139.           return TRUE;
  140.         }
  141.         else
  142.           return FALSE;
  143.           }
  144.       case IDOK:
  145.           Index = SendMessage(ListBoxHandle, LB_GETCURSEL, 0, 0);
  146.           if (Index != LB_ERR)
  147.           // A Project File is currently selected
  148.           {
  149.         SendMessage(ListBoxHandle, LB_GETTEXT, Index, (LPARAM) (char FAR*) FileName);
  150.         EWEditFile(FileName);
  151.           }
  152.           else
  153.           {
  154.         MessageBeep(0);
  155.         EWMessageBox(GetFocus(),
  156.                  "No Project File Selected.",
  157.                  szError,
  158.                  MB_OK | MB_ICONEXCLAMATION);
  159.           };
  160.       case IDCANCEL:
  161.           EndDialog(hwndDlg, IDCANCEL);
  162.           return TRUE;
  163.     }
  164.  
  165.      default:
  166.        return FALSE;
  167.   }
  168. }
  169.  
  170. int FAR PASCAL EWExecute(unsigned int RoutineId)
  171. {
  172.   DLGPROC ChoiceProc;
  173.   UINT      nVersion = EWGetVersion();
  174.  
  175.   // Check version number
  176.   if ((HIBYTE(nVersion) < 2) || ((HIBYTE(nVersion) == 2) && (LOBYTE(nVersion) < 2)))
  177.   {
  178.     EWMessageBox(GetFocus(),
  179.          "This Extension DLL needs E! version 2.02 or newer.",
  180.          szError,
  181.          MB_OK | MB_ICONEXCLAMATION);
  182.     return(ewerr_EXTFAILED);
  183.   }
  184.  
  185.   if (EWGetPrjName(PrjName) == 0)
  186.   {
  187.     ChoiceProc = (DLGPROC) MakeProcInstance(ChoiceDlg, hInst);
  188.     DialogBox(hInst, "Picklist", GetFocus(), ChoiceProc);
  189.     FreeProcInstance((FARPROC) ChoiceProc);
  190.     return 0;
  191.   }
  192.   else
  193.     return(ewerr_EXTFAILED);
  194. }
  195.  
  196.  
  197. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  198.             LPSTR lpszCmdLine)
  199. {
  200.   hInst = hInstance;
  201.   if (wHeapSize > 0)
  202.     UnlockData (0) ;
  203.   return 1;
  204. }
  205.  
  206.